//
//  ModifyPWDViewController.m
//  DuBai
//
//  Created by lt on 14-4-1.
//  Copyright (c) 2014年 darktm. All rights reserved.
//

#import "ModifyPWDViewController.h"

#import "TaskWithModifyPWD.h"

@interface ModifyPWDViewController ()<WYHttpTaskDelegate>

@property (nonatomic,strong)MBProgressHUD *mb;

@end

@implementation ModifyPWDViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.txtNewPWD1.layer.borderColor = [[UIColor darkGrayColor] colorWithAlphaComponent:.4].CGColor;
    self.txtNewPWD1.layer.borderWidth = 1.0f;
    
    self.txtNewPWD2.layer.borderColor = [[UIColor darkGrayColor] colorWithAlphaComponent:.4].CGColor;
    self.txtNewPWD2.layer.borderWidth = 1.0f;
    
    self.txtOrgPWD.layer.borderColor = [[UIColor darkGrayColor] colorWithAlphaComponent:.4].CGColor;
    self.txtOrgPWD.layer.borderWidth = 1.0f;
    
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - http delegate -

-(void)requestCompleteWithObj:(WYHttpTask *)obj{
    
#warning 是否需要重新登录
    
    [self.mb hide:YES afterDelay:0];
    [UIAlertView showAlertViewWithTitle:@"" withMessage:@"密码修改成功" withAction:^(NSInteger index) {
        if(index == 0){
            [self.navigationController popViewControllerAnimated:YES];
        }
    }];
}
-(void)requestFailWithMsg:(WYHttpTask *)obj{
    DLog(@"%@",obj.networkOp.url);
    
    self.mb.labelText = obj.rcvData[@"body"];
    [self.mb hide:YES afterDelay:.8];
}


- (IBAction)on_btn_modify:(id)sender {
    if(!self.txtOrgPWD.text.length){
        [UIAlertView showAlertViewWithTitle:@"原始密码不能为空"];
        return;
    }
    if(!self.txtNewPWD1.text.length){
        [UIAlertView showAlertViewWithTitle:@"新密码不能为空"];
        return;
    }
    if(!self.txtNewPWD2.text.length){
        [UIAlertView showAlertViewWithTitle:@"确认新密码不能为空"];
        return;
    }
    if(![self.txtNewPWD2.text isEqualToString:self.txtNewPWD1.text]){
        [UIAlertView showAlertViewWithTitle:@"两次密码不相同"];
        return;
    }
    
    self.mb = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    
    TaskWithModifyPWD *reg = [[TaskWithModifyPWD alloc] init];
    
    reg.org = self.txtOrgPWD.text;
    reg.nowpwd = self.txtNewPWD1.text;
    reg.delegate = self;
    [reg start];
}
@end
